let baseUrl = "http://127.0.0.1:80";
// 登录接口
let login = "http://localhost:8080/ruge-web-admin/login.html";

let loginMain = baseUrl + "/login/main";
// 验证码接口
let loginCaptcha = baseUrl + "/login/captcha";
// 退出登录
let loginLogout = baseUrl + "/login/logout";
//菜单加载url
let menu = baseUrl + "/login/menu";
// 校验当前用户是否登录
let check = baseUrl + "/login/check";
// 登录日志加载
let loginInfo = baseUrl + "/loginInfo";
// 操作日志加载
let loginOperInfo = baseUrl + "/loginOper";
// 异常日志加载
let loginExcepInfo = baseUrl + "/loginExcep";
// 公告管理
let noticeInfo = baseUrl + "/notice";
// 菜单管理
let menuInfo = baseUrl + "/menu";
// 菜单管理 不分页查询
let menuInfoNoPage = menuInfo + "/noPage";
// 角色管理
let roleInfo = baseUrl + "/role";
// 角色管理 不分页
let roleInfoNoPage = roleInfo + "/noPage";
// 角色授权
let roleInfoAuthMenu = baseUrl + "/role/authMenu";
//获取角色授权菜单进行返显
let roleInfoGetAuthMenu = baseUrl + "/role/getAuthMenu";
//用户管理
let userInfo = baseUrl + "/user";
// 获取当前登录用户
let userInfoSetting = userInfo + "/currentUser";
// 用户授权角色
let userInfoAuthRole = userInfo + "/authRole";
// 用户重置密码
let userInfoResetPwd = userInfo + "/resetPwd";
// 用户密码修改
let userInfoUpdatePwd = userInfo + "/updatePwd";
// 文件上传
let uploadHeadImage = baseUrl + "/upload/headImage";

//下次再发ajax请求把token带到后台
let token = $.cookie('TOKEN');
//设置全局ajax前置拦截
$.ajaxSetup({
    headers: {
        'TOKEN': token   //每次ajax请求时把token带过去
    }
});
//如果访问登陆页面这外的页面并且还没有登陆成功之后写入cookie的token就转到登陆页面
const url = window.location.href;
console.log(url);
if (token == undefined && url!=login) {
    window.top.location = login;
} else {
    if (url.indexOf("login.html") == -1) {
        $.ajax({
            url: check,
            async: true,
            type: 'post',
            success: function (res) {
                if (res.code == -1) {
                    window.top.location = login;
                }
            },
            error: function (res) {
                alert("登录错误");
                window.top.location = login;
            }
        });
    }
}

/*form序列化 start*/
$.fn.serializeObject = function () {
    let o = {};
    let a = this.serializeArray();
    $.each(a, function () {
        if (o[this.name] !== undefined) {
            if (!o[this.name].push) {
                o[this.name] = [o[this.name]];
            }
            o[this.name].push(this.value || '');
        } else {
            o[this.name] = this.value || '';
        }
    });
    return o;
};
$.fn.serializeString = function () {
    let o = {};
    let a = this.serializeArray();
    $.each(a, function () {
        if (o[this.name] !== undefined) {
            if (!o[this.name].push) {
                o[this.name] = [o[this.name]];
            }
            o[this.name].push(this.value || '');
        } else {
            o[this.name] = this.value || '';
        }
    });
    return JSON.stringify(o);
};
/*form序列化 end*/

const activeUser = JSON.parse(localStorage.getItem("activeUser"));
console.log(activeUser);
if (typeof (activeUser) != undefined && null!=activeUser) {
    let userName = activeUser.user.nickName;
    $(".user_name").html(userName);
}


